{include file="admin@public/header"/}
<link rel="stylesheet" href="/public/static/admin/css/report.css" />
<link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css">
<style>
	.ui-icon-ellipsis {
		right: 5px;
	}

	#filter-menu .con {
		width: 355px;
	}

	#filter-menu label.tit {
		width: 80px;
	}

	/*.ui-jqgrid tr.jqgrow td {
	white-space: normal !important;
	}
	*/
	.no-query {
		background: url("/public/static/admin/css/img/no_query.png") no-repeat scroll 100px 60px #fff;
		background-position: center;
		border: 1px solid #ddd;
		border-top: none;
		height: 402px;
		margin-right: 0;
	}

	.box-flex {
		overflow: hidden;
		zoom: 1;
	}

	.box-flex .flex {
		float: left;
		width: 33.3%;
	}

	.grid-title {
		font-size: 24px;
		text-align: center;
		clear: none;
	}

	.ui-print .grid-wrap {
		padding: 10px 0 0 30px;
	}

	#conditions-trigger {
		background: url(/public/static/admin/css/img/bg.png) no-repeat;
		border: 0px;
		width: 74px;
		box-shadow: 0px 0px;
	}

	#filter-menu .conditions-trigger>b {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -8px;
		width: 16px;
		height: 16px;
		background: url(/public/static/admin/css/img/down.png) 2px 5px no-repeat;
	}

	#filter-menu .conditions-trigger>b.act {
		background: url(/public/static/admin/css/img/up.png) 2px 5px no-repeat;
	}

	#filter-menu .btns {
		position: absolute;
		top: 0;
		right: 0px;
	}
</style>

<div class="wrapper">
	<!-- header -->
	<div class="mod-search cf">
		<div class="l" id="filter-menu">
			<ul class="ul-inline fix" id="filterItems" style="height: 44px;">
				<li id="date" style="display: list-item;"><label>单据日期:</label>
					<input type="date" id="startdate" class="ui-input " value="" style="width: 125px;">
					<span class="todate"> 至 </span>
					<input type="date" id="enddate" class="ui-input " value="" style="width: 125px;">
				</li>

				<!-- 选择供应商 -->
				{include file="admin@select/supplier"/}

				<!-- 选择商品 -->
				{include file="admin@select/goods"/}

				<li id="billNum" style="display: list-item;">
					<label>单据编号</label>
					<input type="text" value="" style="width:115px;" class="ui-input ui-input-ph" name="sn" id="sn"
						placeholder="请输入单号查询">
				</li>

				<!-- 选择供应商类别 -->
				{include file="admin@select/supplier_category"/}

				<!-- 选择商品类别 -->
				{include file="admin@select/goods_category"/}

				<!-- 选择仓库 -->
				{include file="admin@select/store"/}

				<li id="billsNo" style="display: list-item;">
					<label>源订单号:</label>
					<input type="text" class="ui-input ui-input-ph" id="billsNoAuto">
				</li>
				<li id="remarks" style="display: list-item;">
					<label>整单备注:</label>
					<input type="text" value="" class="ui-input ui-input-ph" name="mark" id="mark" style="width: 120px;"
						placeholder="请输入备注查询">
				</li>




				<div class="btns"><a class="ui-btn mrb ui-btn-search" id="filter-submit">查询</a></div>
				<!-- <span class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5713" target="_blank" class="video-icon" style="margin-right: 5px;"></a>功能简介</span> -->
			</ul>
			<a href="#" id="conditions-trigger" class="ui-btn conditions-trigger" tabindex="-1">&nbsp;更多条件<b></b></a>
		</div>
	</div>

	<!-- 下拉树选择（供应商类别） -->
	{include file="admin@popup/supplier_category"/}
	<!-- 下拉树选择（商品类别） -->
	{include file="admin@popup/goods_category"/}

	<!-- no data -->
	<div class="no-query"></div>
	<!-- grid begin -->
	<div class="ui-print" id="ui-print" style="visibility: hidden;">
		<!-- 列配置 -->
		<div class="cf box-flex">
			<div class="flex">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>

			<div class="grid-title flex">商品采购明细表</div>
			<div class="fr">
				<a href="#" class="ui-btn ui-btn-export btn-sm mrb fl" id="btn-export">导出</a>
				<a href="javascript:void(0)" class="ui-btn ui-btn-print btn-sm fl" id="btn-print"
					onclick="preview(1)">打印</a>
			</div>
		</div>

		<div class="grid-wrap" id="grid-wrap" style="padding-bottom: 30px;padding-right: 30px;">
			<!--startprint-->
			<!-- <div class="grid-title">商品采购明细表</div> -->
			<div class="grid-subtitle"></div>
			<table id="grid"></table>
			<!--endprint-->
			<div id="page"></div>
		</div>
	</div>
	<!-- grid end -->

	<!--  以隐藏的方式获取商品的样式 ，作用是赋值 -->
	<div style="display:none;">
		<input type="text" id="supplierid" value="" autocomplete="off" readonly="">

		<input type="text" id="goodsid" value="" autocomplete="off" readonly="">
		<input type="text" id="goodsname" value="" autocomplete="off" readonly="">
		<input type="text" id="goodstype" value="" autocomplete="off" readonly="">
		<input type="text" id="goodsmark" value="" autocomplete="off" readonly="">
		<input type="text" id="goodsdw" value="" autocomplete="off" readonly="">
	</div>
</div>

<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/public/static/admin/js/jquery-migrate-1.0.0.js"></script>
<script type="text/javascript" src="/public/static/admin/js/jquery.jqprint-0.3.js"></script>


<script>
	$(document).ready(function () {
		// 获取当前日期
		var myDate = new Date;
		var year = myDate.getFullYear(); //获取当前年
		var mon = myDate.getMonth() + 1; //获取当前月
		var date = myDate.getDate(); //获取当前日
		// console.log(year + '-' + mon + '-' + date)
		if (mon < 10) {
			mon = "0" + mon;
		}
		if (date < 10) {
			date = "0" + date;
		}
		$("#startdate").val(year + '-' + mon + '-01');
		$("#enddate").val(year + '-' + mon + '-' + date);
	});
</script>

<script type="text/javascript">

	$(document).ready(function () {

		var doubleclick = "{$doubleclick}";
		if (doubleclick == 1) {
			$("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示
			$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");

		}

		// 点击查询按钮
		$("#filter-submit").click(function () {

			$("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示

			// 设置表格高度
			$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");

			var startdate = $('#startdate').val();
			var enddate = $('#enddate').val();
			var supplierid = $('#supplier_id').val();
			var goods_id = $('#goods_id').val();
			var store_id = $('#store_id').val();
			var mark = $('#mark').val();
			var sn = $('#sn').val();
			var supplier_category_id = $('#supplier_category_id').val();
			var goods_category_id = $('#goods_category_id').val();
			$("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);

			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: {
					'ajax': '100',
					'startdate': startdate,
					'enddate': enddate,
					'supplierid': supplierid,
					'goods_id': goods_id,
					sn: sn,
					store_id: store_id,
					mark: mark,
					supplier_category_id: supplier_category_id,
					goods_category_id: goods_category_id
				}, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
		});

		//alert("1111");
		$("#grid").jqGrid({
			// url: "/scm/invpureport/index.html?ajax=100&store_id={$store_id|default=''}&goods_id={$goods_id|default=''}",
			url: "/scm/invpureport/index.html",
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["", "采购日期", "采购单据号", "业务类别", "供应商", "商品编号", "商品名称", "商品条码", "规格型号", "单位", "仓库", "数量", "单价", "含税单价", "采购金额", "采购费用", "税额", "价税合计", "源购货订单号", "分录备注", "整单备注", "o_type"],
			colModel: [
				{ name: 'id', index: 'id', width: 110, hidden: true },
				{ name: 'addtime', width: 80 },
				{ name: 'sn', index: 'name asc', width: 150 },
				{ name: 'o_type_name', index: 'name asc', width: 60 },
				{ name: 'customer_name', index: 'name asc', width: 100 },
				{ name: 'goods_sn', index: 'name asc', width: 80 },
				{ name: 'goods_name', index: 'name asc', width: 120 },
				{ name: 'goods_code', index: 'name asc', width: 120 },
				{ name: 'goods_model', index: 'name asc', width: 120 },
				{ name: 'unit_name', index: 'name asc', width: 50, align: "center" },
				{ name: 'store_name', index: 'name asc', width: 100 },
				{ name: 'number', index: 'name asc', width: 100, align: "right" },
				{ name: 'price', index: 'name asc', width: 100, align: "right" },
				{ name: 'total_tax_price', index: 'name asc', width: 100, align: "right" },
				{ name: 'payment', index: 'name asc', width: 100, align: "right" },
				{ name: 'purchase_price', index: 'name asc', width: 100, align: "right" },
				{ name: 'tax_price', index: 'name asc', width: 100, align: "right" },
				{ name: 'sum_price_tax', index: 'name asc', width: 100, align: "right" },
				{ name: 'purchase_sn', index: 'name asc', width: 200 },
				{ name: '', index: 'name asc', width: 180 },
				{ name: 'mark', index: 'name asc', width: 150 },
				{ name: 'o_type', hidden: true },
			],
			rowNum: 500,
			rowList: [500, 1000, 5000],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置

			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			// 合计
			footerrow: true,
			gridComplete: function () {
				var numbers = parseFloat($("#grid").getCol('number', false, 'sum')).toFixed(2);
				var prices = parseFloat($("#grid").getCol('price', false, 'avg')).toFixed(2);
				var payment = parseFloat($("#grid").getCol('payment', false, 'sum')).toFixed(2);
				var purchase_prices = parseFloat($("#grid").getCol('purchase_price', false, 'sum')).toFixed(2);
				var tax_prices = parseFloat($("#grid").getCol('tax_price', false, 'sum')).toFixed(2);
				var sum_price_taxs = parseFloat($("#grid").getCol('sum_price_tax', false, 'sum')).toFixed(2);
				$("#grid").footerData('set', { "addtime": '合计:', number: numbers, price: prices, payment: payment, purchase_price: purchase_prices, tax_price: tax_prices, sum_price_tax: sum_price_taxs });

				// 合并合计单元格
				var $footRow = $("#grid").closest(".ui-jqgrid-bdiv").next(".ui-jqgrid-sdiv").find(".footrow");
				$footRow.find('>td[aria-describedby="grid_addtime"],>td[aria-describedby="grid_sn"],>td[aria-describedby="grid_o_type_name"],>td[aria-describedby="grid_type_name"],>td[aria-describedby="grid_customer_name"],>td[aria-describedby="grid_goods_sn"],>td[aria-describedby="grid_goods_name"],>td[aria-describedby="grid_goods_code"],>td[aria-describedby="grid_goods_model"],>td[aria-describedby="grid_unit_name"]').css("border-right-color", "transparent");
			},
			//双击表格行事件
			ondblClickRow: function (row) {
				var rowData = $('#grid').jqGrid('getRowData', row);
				if (rowData.o_type == 4) {
					parent.tab.addTabItem({
						tabid: "purchase-purchase2",
						text: "购货单",
						url: "/scm/invpu/edit.html?id=" + rowData.id,
					})
				} else {
					parent.tab.addTabItem({
						tabid: "purchase-purchase2",
						text: "退货单",
						url: "/scm/invre/edit.html?id=" + rowData.id,
					})
				}

			}
		});

		var headH = 0;  //顶部搜索是否展开（1：展开，0：未展开）
		$("#conditions-trigger").click(function () {
			if (headH == 0) {
				headH = 1;
				$("#filterItems").css({ "height": "auto" });
				$(this).html("&nbsp;收起条件<b class='act'></b>");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");
			} else {
				headH = 0;
				$("#filterItems").css({ "height": "44px" });
				// $("#filterItems").animate({height:'44px'});
				$(this).html("&nbsp;更多条件<b></b>");
				// 设置表格高度
				$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");
			}
		});



	});
	$("#btn-export").click(function () {
		var page = $('#grid').getGridParam('page'); // current page
	    var rows = $('#grid').getGridParam('rowNum'); // rows
	    var startdate = $("#startdate").val();
		var enddate = $("#enddate").val();
	    var rowData = $("#grid").getRowData();
	    var rowid = '';
	    rowData.forEach(function(a,b,c){
	    	rowid += a['id']+' ';
	    })
		window.location.href = 'export?rowid='+rowid+'&startdate='+startdate+'&enddate='+enddate;
	})



</script>



{include file="admin@public/footer"/}